## 设置 git 提示符
# Import-Module "$env:SCOOP\apps\posh-git\current\posh-git"
Import-Module "posh-git"
$GitPromptSettings.DefaultPromptBeforeSuffix.Text = '`n'
# $GitPromptSettings.DefaultPromptPrefix.Text = '`nPS $env:UserName@$env:ComputerName '
# $GitPromptSettings.DefaultPromptPrefix.ForegroundColor = [ConsoleColor]::Magenta
## 使提示符正常显示。否则会显示控制序列字符。
# $GitPromptSettings.AnsiConsole = $false

# Import-Module "PSReadLine"
# Import-Module "$env:SCOOP\apps\PSReadLine\current\PSReadLine"
# 搜索历史时(↑)移动光标到行未而不是行首
Set-PSReadLineOption -HistorySavePath "D:\Temp\psreadlinehistory.txt"
Set-PSReadLineOption -HistorySearchCursorMovesToEnd
Set-PSReadLineOption -EditMode Windows
# TAB补全时提供可选择菜单
Set-PSReadLineKeyHandler -Key "Tab" -Function MenuComplete

if (get-module "posh-git") {
    function prompt {
        $loc = Get-Location
        $prompt = & $GitPromptScriptBlock
        $prompt = "$([char]27)[45mPS$([char]27)[0m " + $prompt
        $prompt += "$([char]27)]9;12$([char]7)"
        if ($loc.Provider.Name -eq "FileSystem") {
            $prompt += "$([char]27)]9;9;`"$($loc.ProviderPath)`"$([char]27)\"
        }
        $prompt
    }
} else {
    function prompt {
        $loc = Get-Location
        $cd = $loc.path
        $out = "$([char]27)[45mPS$([char]27)[40m $([char]27)[32m$cd$([char]27)[40m`n>$([char]27)[0m "
        if ($loc.Provider.Name -eq "FileSystem") {
            $out += "$([char]27)]9;9;`"$($loc.ProviderPath)`"$([char]27)\"
        }
        return $out
    }
}
